package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "护理项目相关接口")
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @ApiOperation("分页条件查询")
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(@ApiParam(value = "护理项目名称") @RequestParam(required = false) String name,
                                                                    @ApiParam(value = "状态") @RequestParam(required = false) Integer status,
                                                                    @ApiParam(value = "页码") @RequestParam(required = true, defaultValue = "1") Integer pageNum,
                                                                    @ApiParam(value = "条数") @RequestParam(required = true, defaultValue = "10") Integer pageSize){
        PageResponse<NursingProjectVo> pageVo = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(pageVo);
    }

    @ApiOperation("新增")
    @PostMapping
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.addNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }

    @ApiOperation("根据id查询护理项目")
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id){
        NursingProjectVo vo = nursingProjectService.getById(id);
        return ResponseResult.success(vo);
    }
    @ApiOperation("编辑")
    @PutMapping
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseResult delById(@PathVariable Long id){
        nursingProjectService.delById(id);
        return ResponseResult.success();
    }
    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult enableOrDisable(@PathVariable Long id,
                                          @PathVariable Integer status){
        nursingProjectService.enableOrDisable(id, status);
        return ResponseResult.success();
    }

}
